package com.flywen.generic;

import com.alibaba.fastjson.JSON;

import java.io.Serializable;

public class GenericResponse<T> implements Serializable {
    private static final long serialVersionUID = -4172955148660342349L;
    private String responseCode = "0000";
    private String responseMsg = "success";
    private T object;

    public GenericResponse(T object) {
        this.object = object;
    }

    public GenericResponse() {
    }

    public boolean isSuccess() {
        return "0000".equals(this.responseCode);
    }

    public static <T> GenericResponse<T> success(T data) {
        return new GenericResponse(data);
    }

    public GenericResponse<T> fail(String responseCode, String responseMsg) {
        this.responseCode = responseCode;
        this.responseMsg = responseMsg;
        return this;
    }

    public String getResponseCode() {
        return this.responseCode;
    }

    public void setResponseCode(String responseCode) {
        this.responseCode = responseCode;
    }

    public String getResponseMsg() {
        return this.responseMsg;
    }

    public void setResponseMsg(String responseMsg) {
        this.responseMsg = responseMsg;
    }

    public String toString() {
        return JSON.toJSONString(this);
    }

    public T getObject() {
        return this.object;
    }

    public void setObject(T object) {
        this.object = object;
    }
}
